<template>
  <div class="register">
    <div class="regbox">
      <div class="reg-title">
        <h2>补发商标注册证申请</h2>
      </div>
      <div class="reg-form">
        <el-form
          :model="ruleForm"
          :rules="rules"
          ref="ruleForm"
          label-width="200px"
          class="demo-ruleForm"
        >
          <el-form-item label="申请人名称：" prop="pledgee">
            <el-input v-model="ruleForm.pledgee" disabled="disabled"></el-input>
          </el-form-item>
          <el-form-item label="商标注册号：" prop="app_code">
            <el-input v-model="ruleForm.app_code" placeholder="商标注册号"></el-input>
          </el-form-item>
          <el-form-item label="是否共有商标：" prop="comm_status">
            <el-radio-group v-model="ruleForm.comm_status">
              <el-radio :label="1">是</el-radio>
              <el-radio :label="0">否</el-radio>
            </el-radio-group>
          </el-form-item>

          <el-form-item label="文本域：" prop="reasons">
            <el-input type="textarea" v-model="ruleForm.reasons" :autosize="{ minRows: 5}"></el-input>
          </el-form-item>

          <base-upload @getFile="getFile"></base-upload>
        </el-form>
      </div>
      <div class="r-f-sutbox">
        <button class="r-f-sut" @click="subForm('ruleForm')">提交</button>
      </div>
    </div>
  </div>
</template>

<script>
import BaseUpload from "@/components/base-component/BaseUpload";
export default {
  name: "form-reissueapply",
  components: {
    BaseUpload
  },
  data() {
    return {
      formData: new FormData(),

      ruleForm: {
        pledgee: "asd",
        app_code: "",
        comm_status: 1,
        reasons: "",
        docImgs: [],
        confirmImgs: null
      },
      rules: {
        pledgee: [{ required: true, message: "字段不能为空", trigger: "blur" }],
        app_code: [
          { required: true, message: "字段不能为空", trigger: "blur" }
        ],
        comm_status: [
          { required: true, message: "字段不能为空", trigger: "change" }
        ],
        reasons: [{ required: true, message: "字段不能为空", trigger: "blur" }]
      }
    };
  },
  methods: {
    // 获取数据
    getFile(data, data2) {
      this.ruleForm.docImgs = data;
      this.ruleForm.confirmImgs = data2;
    },
    subForm(formName) {
      this.$refs[formName].validate(valid => {
        if (valid) {
          this.ruleForm.docImgs.forEach(element => {
            this.formData.append("docImgs", element);
          });
          this.ruleForm.confirmImgs.forEach(element => {
            this.formData.append("confirmImgs", element);
          });
          // this.formData.append("pledgee", this.ruleForm.pledgee);
          this.formData.append("app_code", this.ruleForm.app_code);
          this.formData.append("comm_status", this.ruleForm.comm_status);
          this.formData.append("reasons", this.ruleForm.reasons);


          // axios向后端发送数据
          this.$http
            .post(
              "/proTReissue/update",
              this.formData,
            )
            .then(function(response) {
              console.log(response);
            })
            .catch(function(error) {
              console.log(error);
            });
        } else {
          alert("提交失败");
          return false;
        }
      });
    }
  }
};
</script>

<style scoped lang="less">
.fade-enter-active,
.fade-leave-active {
  transition: opacity 0.5s;
}
.fade-enter, .fade-leave-to /* .fade-leave-active, 2.1.8 版本以下 */ {
  opacity: 0;
}
i,
em {
  font-style: normal;
}
.register {
  width: 100%;
  background-color: #e7e8eb;
  .regbox {
    width: 1240px;
    margin: 0 auto;
    background-color: #fff;
    padding: 20px;
    .reg-title {
      padding: 15px 20px;
      text-align: center;
      border-bottom: 1px solid #e7e8eb;
      h2 {
        font-size: 22px;
        font-weight: 300;
      }
    }
    .reg-form {
      width: 700px;
      margin-left: 120px;
      .el-form-item {
        margin-top: 50px;
      }
    }

    .r-f-sutbox {
      margin-top: 50px;
      text-align: center;
      .r-f-sut {
        padding: 12px 20px;
        color: #fff;
        border: none;
        outline: none;
        border-radius: 5px;
        cursor: pointer;
        background-color: #67c23a;
      }
    }
  }
}
</style>
